import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_app/openeye/config/string.dart';
import 'package:flutter_app/openeye/utils/toast_utils.dart';
import 'package:flutter_app/router/unit_router.dart';
import 'package:flutter_app/stateLearn/click_txt.dart';
import 'package:flutter_app/ui/page_two.dart';
import 'package:get/get.dart';

class HomePage extends StatefulWidget {
  const HomePage({Key? key}) : super(key: key);

  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  DateTime? lastClick;

  @override
  Widget build(BuildContext context) {
    return WillPopScope(
      onWillPop: _onWillPop,
      child: Scaffold(
        appBar: AppBar(
          title: const Text("Home"),
        ),
        body: ListView(
          children: <Widget>[
            TextButton(
                onPressed: () {
                  routePage(context);
                },
                child: const Text(
                  "第二页",
                  style: TextStyle(fontSize: 28),
                )),
            TextButton(
                onPressed: () {
                  Navigator.pushNamed(context, "pageTest");
                },
                child: const Text("页面测试", style: TextStyle(fontSize: 28))),
            TextButton(
                onPressed: () {
                  Navigator.pushNamed(context, "animation1");
                },
                child: const Text("动画", style: TextStyle(fontSize: 28))),
            TextButton(
                onPressed: () {
                  Navigator.pushNamed(context, "sharePageFirst");
                },
                child: const Text("共享元素", style: TextStyle(fontSize: 28))),
            TextButton(
                onPressed: () {
                  Navigator.pushNamed(context, "statusManager");
                },
                child: const Text("状态管理", style: TextStyle(fontSize: 28))),
            TextButton(
                onPressed: () {
                  Navigator.pushNamed(context, "openEyeHome");
                },
                child: const Text("开眼视频功能页面", style: TextStyle(fontSize: 28))),
            TextButton(
                onPressed: () {
                  Navigator.pushNamed(context, "statePage");
                },
                child: const Text("状态管理测试页面", style: TextStyle(fontSize: 28))),
            TextButton(
                onPressed: () {
                  Navigator.pushNamed(context, "asyncLoad");
                },
                child: const Text("异步加载测试页面", style: TextStyle(fontSize: 28))),
            TextButton(
                onPressed: () {
                  Navigator.pushNamed(context, "otherAPITest");
                },
                child:
                    const Text("一些其他的api测试页面", style: TextStyle(fontSize: 28))),
            TextButton(
                onPressed: () {
                  Navigator.pushNamed(context, "jsonTest");
                },
                child:
                    const Text("测试mod实例化页面", style: TextStyle(fontSize: 28))),
            TextButton(
                onPressed: () {
                  Navigator.pushNamed(context, "imageLoading");
                },
                child: const Text("图片加载测试页面", style: TextStyle(fontSize: 28))),
            TextButton(
                onPressed: () {
                  Navigator.pushNamed(context, "counter");
                },
                child: const Text("计算器页面", style: TextStyle(fontSize: 28))),
            TextButton(
                onPressed: () {
                  Navigator.pushNamed(context, "pageTest");
                },
                child: const Text("页面权重，编辑", style: TextStyle(fontSize: 28))),
            TextButton(
                onPressed: () {
                  Navigator.pushNamed(context, "demoJueJInMe");
                },
                child: const Text("组合页面", style: TextStyle(fontSize: 28))),
            TextButton(
                onPressed: () {
                  Navigator.pushNamed(context, "demoFlowPopMenu");
                },
                child: const Text("展开收起菜单", style: TextStyle(fontSize: 28))),
            TextButton(
                onPressed: () {
                  Navigator.pushNamed(context, "demoFlowMenu");
                },
                child: const Text("展开收起菜单2", style: TextStyle(fontSize: 28))),
            TextButton(
                onPressed: () {
                  Navigator.pushNamed(context, "containerTest")
                      .then((value) {});
                },
                child: const Text("定位装饰组件", style: TextStyle(fontSize: 28))),
            TextButton(
                onPressed: () {
                  Navigator.of(context).maybePop();
                },
                child: const Text("pop方法测试", style: TextStyle(fontSize: 28))),
            TextButton(
                onPressed: () {
                  Navigator.pushNamed(context, "partNavigator");
                },
                child: const Text("局部nav设置", style: TextStyle(fontSize: 28))),
            TextButton(
                onPressed: () {
                  Navigator.pushNamed(context, "getXTest");
                },
                child: const Text("getX测试", style: TextStyle(fontSize: 28))),
            TextButton(
                onPressed: () {
                  Navigator.pushNamed(context, "sqfLite");
                },
                child: const Text("数据库试用测试", style: TextStyle(fontSize: 28))),
            TextButton(
                onPressed: () {
                  Navigator.pushNamed(context, "picSelect");
                },
                child: const Text("图片选择测试", style: TextStyle(fontSize: 28))),
            TextButton(
                onPressed: () {
                  Navigator.pushNamed(context, "shareInfo");
                },
                child: const Text("分享功能测试", style: TextStyle(fontSize: 28))),
            TextButton(
                onPressed: () {
                  Navigator.pushNamed(context, "httpTest");
                },
                child: const Text("网络请求测试", style: TextStyle(fontSize: 28))),
            TextButton(
                onPressed: () {
                  Navigator.pushNamed(context, "getViewOneTest");
                },
                child: const Text("GetView测试", style: TextStyle(fontSize: 28))),
            TextButton(
                onPressed: () {
                  Navigator.pushNamed(context, "sliverViewTest");
                },
                child: const Text("sliver组件功能测试", style: TextStyle(fontSize: 28))),
            TextButton(
                onPressed: () {
                  Navigator.pushNamed(context, "storageTest");
                },
                child: const Text("数据持久化测试", style: TextStyle(fontSize: 28))),
            TextButton(
                onPressed: () {
                  Navigator.pushNamed(context, "shimmerTest");
                },
                child: const Text("骨架屏测试", style: TextStyle(fontSize: 28))),
            TextButton(
                onPressed: () {
                  Navigator.pushNamed(context, "slidableTest");
                },
                child: const Text("侧滑删除测试", style: TextStyle(fontSize: 28))),
            TextButton(
                onPressed: () {
                  Navigator.pushNamed(context, "refreshDart");
                },
                child: const Text("上拉加载，下拉刷新测试", style: TextStyle(fontSize: 28))),
            TextButton(
                onPressed: () async{
                  // Get.offNamedUntil(page, (route) => false);
               var params =  await Get.toNamed(UnitRouter.paramsTest,arguments: {"index":12});
               print(params);
                },
                child: const Text("参数传递测试", style: TextStyle(fontSize: 28))),
            TextButton(
                onPressed: () {
                  Get.toNamed("参数传递测试");
                },
                child: const Text("测试路由", style: TextStyle(fontSize: 28))),
            TextButton(
                onPressed: () {
                  Get.toNamed(UnitRouter.jgPushTest);
                },
                child: const Text("极光推送测试", style: TextStyle(fontSize: 28))),
            TextButton(
                onPressed: () {
                  Get.toNamed(UnitRouter.jgCountTest);
                },
                child: const Text("极光统计测试", style: TextStyle(fontSize: 28))),
            TextButton(
                onPressed: () {
                  Get.toNamed(UnitRouter.versionFlutter);
                },
                child: const Text("版本管理测试", style: TextStyle(fontSize: 28))),
            TextButton(
                onPressed: () {
                  Get.toNamed(UnitRouter.nativeConnect);
                },
                child: const Text("与原生通讯测试", style: TextStyle(fontSize: 28))),
            TextButton(
                onPressed: () {
                  Navigator.pushNamed(context, "webViewExample");
                },
                child: const Text("网页加载测试", style: TextStyle(fontSize: 28))),
            TextButton(
                onPressed: () {
                  Navigator.pushNamed(context, "WebFlutter");
                },
                child: const Text("WebViewFlutter加载测试", style: TextStyle(fontSize: 28))),
            TextButton(
                onPressed: () {
                  Navigator.pushNamed(context, "InAppWebViewTest");
                },
                child: const Text("InAppWebViewFlutter加载测试", style: TextStyle(fontSize: 28))),
            TextButton(
                onPressed: () {
                  Navigator.pushNamed(context, "InAppWebViewExampleScreen");
                },
                child: const Text("OtherInAppWebViewFlutter加载测试", style: TextStyle(fontSize: 28))),
            TextButton(
                onPressed: () {
                  Navigator.pushNamed(context, "BackTest");
                },
                child: const Text("返回按钮功能测试", style: TextStyle(fontSize: 28))),
            TextButton(
                onPressed: () {
                  Navigator.pushNamed(context, "SavePicTest");
                },
                child: const Text("图片下载功能开发测试", style: TextStyle(fontSize: 28))),
            TextButton(
                onPressed: () {
                  Navigator.pushNamed(context, "updatePopTest");
                },
                child: const Text("版本更新弹窗测试", style: TextStyle(fontSize: 28))),
            TextButton(
                onPressed: () {
                  Navigator.pushNamed(context, "overlayToolPage");
                },
                child: const Text("悬浮球测试", style: TextStyle(fontSize: 28))),
            TextButton(
                onPressed: () {
                  Navigator.pushNamed(context, "textRichTest");
                },
                child: const Text("图文混排功能测试", style: TextStyle(fontSize: 28))),
            TextButton(
                onPressed: () {
                  Navigator.pushNamed(context, "signArgsPage");
                },
                child: const Text("参数签名测试页面", style: TextStyle(fontSize: 28))),
            TextButton(
                onPressed: () {
                  Navigator.pushNamed(context, "colorPage");
                },
                child: const Text("颜色测试页面", style: TextStyle(fontSize: 28))),
            TextButton(
                onPressed: () {
                  Navigator.pushNamed(context, "lottieTest");
                },
                child: const Text("lottie动画测试", style: TextStyle(fontSize: 28))),
          ],
        ),
      ),
    );
  }

  routePage(BuildContext context) {
    Navigator.push(context,
        PageRouteBuilder(pageBuilder: (context, animation, secondaryAnimation) {
      return SlideTransition(
        position: Tween<Offset>(
                begin: const Offset(1.0, 0.0), end: const Offset(0.0, 0.0))
            .animate(animation),
        child: PageTwo(),
      );
    }));
  }

  Future<bool> _onWillPop() async {
    if (lastClick == null
        ? true
        : DateTime.now().difference(lastClick!) > const Duration(seconds: 2)) {
      lastClick = DateTime.now();
      ToastUtils.showTip(LeoString.back_app);
      return false;
    } else {
      return true;
    }
  }
}
